<?php
namespace app\common\model;

trait BaseLog {
  //protected $foreignKey;

  public function logOne($data){
    $query=$this->logs();
    //$query=$query->data($data);
    $data[$this->foreignKey]=$this->getAttr($this->getPk());
    $data['happen_time']=date("Y-m-d h:i:s",time());
    $validate=validate($this->name.'Log');
    if (!$validate->check($data)){
      $this->error=$validate->getError();
      return false;
    }
    try{
      if ($query->save($data)){
        return true;
      } else {
        $this->error='新增log失败';
      }
    } catch (\Exception $e){
      $this->error='新增log失败（数据库异常）'.$e->getMessage();
    }
    return false;
  }

}
